#include<bits/stdc++.h>
using namespace std;
int t,n,a[100010],cnt[100010];
int main(){


    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);




    cin>>t;
    while(t--){
        int ans=0;
        cin>>n;
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        int sum=1;
        for(int i=1;i<=n;i++){
            if(a[i]==a[i+1]){
                cnt[sum]++;
                ans+=a[i];
            }
            else sum++;
        }
        cout<<ans<<endl;
    }
    return 0;
}
